/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: AliPayStrategy
 * Author:   zhouheng
 * Date:     2019/5/15 0:16
 * Description: 支付宝支付策略
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.star.pay.service.core.strategy;

import com.star.pay.bean.PayServiceRequest;
import com.star.pay.service.core.common.PayChannelEnum;
import com.star.pay.service.core.common.PaymentResponseEnum;
import com.star.pay.service.core.exception.PayException;
import com.star.pay.service.core.processor.PayProcessor;
import com.star.pay.service.core.processor.context.AliPayContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 〈一句话功能简述〉<br> 
 * 〈支付宝支付策略〉
 *
 * @author zhouheng
 * @create 2019/5/15
 * @since 1.0.0
 */
@Component
public class AliPayStrategy extends PayStrategy{

    @Autowired
    private PayProcessor baseProcessor;

    @Override
    public String generatePrepalOrder(PayServiceRequest payServiceRequest) throws PayException {
        // 封装阿里支付上下文
        AliPayContext aliPayContext = new AliPayContext();
        aliPayContext.setOutTradeNo(payServiceRequest.getTradeNo());
        aliPayContext.setSubject(payServiceRequest.getSubject());
        aliPayContext.setTotalFee(payServiceRequest.getTotalFee().doubleValue()/100);
        aliPayContext.setPayChannelEnum(PayChannelEnum.ALI_PAY);

        // 支付处理
        baseProcessor.process(aliPayContext);

        if (aliPayContext.getResCode() == PaymentResponseEnum.SUCCESS.getCode()){
        }

        return null;
    }

    @Override
    public String getPayChannel() {
        return  PayChannelEnum.ALI_PAY.getCode();
    }
}